package com.sharelogindemo.wxapi;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.wechat.friends.Wechat;

/**
 * Created by 1 on 2017/10/16.
 */

public class WeiChatShareUtil {

    /**
     * 分享文本
     * @param title 分享的标题
     * @param listener 分享回调
     * @return
     */
    public void shareTextPassWeiXin(String shareadress,String title, PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        Platform weixin = ShareSDK.getPlatform (shareadress);
        sp.setText(title);
        sp.setTitle(title);
        sp.setShareType(Platform.SHARE_TEXT);
        weixin.setPlatformActionListener(listener);
        weixin.share(sp);
    }

    /**
     * 分享图片
     * @param imageUrl
     * @param listener
     */

    public void sharePicPassWeiXin(String shareadress, String imageUrl, PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        Platform weixin = ShareSDK.getPlatform (shareadress);
        sp.setShareType(Platform.SHARE_IMAGE);
        if(imageUrl.contains("http")){
            sp.setImageUrl(imageUrl);
        }else {
            sp.setImagePath(imageUrl);
        }
        weixin.setPlatformActionListener(listener);
        weixin.share(sp);
    }

    /**
     * 分享网页
     * @param title
     * @param imageUrl
     * @param listener
     */
    public void shareWebPagePassWeiXin(String title, String imageUrl, PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        Platform weixin = ShareSDK.getPlatform (Wechat.NAME);
        sp.setTitle(title);
        sp.setShareType(Platform.SHARE_WEBPAGE);
        if(imageUrl.contains("http")){
            sp.setImageUrl(imageUrl);
        }else {
            sp.setImagePath(imageUrl);
        }
        weixin.setPlatformActionListener(listener);
        weixin.share(sp);
    }

    /**
     * 分享视频
     * @param title
     * @param imageUrl
     * @param videoUrl
     * @param listener
     */
    public void shareVideoPassWeiXin(String title, String imageUrl,String videoUrl, PlatformActionListener listener){
        Platform.ShareParams sp = new Platform.ShareParams();
        Platform weixin = ShareSDK.getPlatform (Wechat.NAME);
        sp.setTitle(title);
        sp.setShareType(Platform.SHARE_VIDEO);
        sp.setUrl(videoUrl);

        if(imageUrl.contains("http")){
            sp.setImageUrl(imageUrl);
        }else {
            sp.setImagePath(imageUrl);
        }
        weixin.setPlatformActionListener(listener);
        weixin.share(sp);
    }

}
